<!-- 快递寄件订单管理 -->
<template>
<div class="content-box">
  <FilterBox
    :labelWidth="120"
    :filterItemList="filterItemList"
    :filterData="filterData"
    @search="search"
    @clear="clear"
    @keep="keepHeaderList"
  >
  </FilterBox>
  <MyTable
    :tableColumn="tableColumn"
    :tableData="tableData"
    :isOrder="false"
    @sendCurrentData="setCurrent"
    @cellDblclick="cellDblclick"
    >
    <template v-slot:content="scope">
      <span class="moreContant" v-if="!!scope.config.MoreContant">
        <span v-for="(item,k) in scope.config.MoreContant" :key="k">
          <span v-if="!item.istooltip">{{item.label}}:{{scope.row[item.prop]}}</span>
          <span v-else>
            {{item.label}}:
            <el-tooltip class="tooltip" :content="scope.row[item.prop]" placement="bottom-start" effect="dark">
                <span>{{scope.row[item.prop]}}</span>
            </el-tooltip>
            </span>
        </span>
      </span>
      <span class="moreContant" v-else-if="!!scope.config.is_additional">
        <span v-for="(item,k) in scope.row.items" :key="k">
          {{item.name_current}}:{{item.val}}
        </span>
      </span>
      <span v-else>{{ scope.row[scope.config.prop] }}</span>
    </template>
  </MyTable>
  <!-- 分页组件 -->

  <Pagination
    :currentPage="pageinfo.page"
    :pageSize="pageinfo.limit"
    :total="pageinfo.number_all"
    :page_all="pageinfo.page_all"
    @pagination="SetPagination"
    @sendPushButton="pushButton"
  >
  </Pagination>

  <Add
    @success="getTableData"
    ref="add"
  ></Add>
  <Edit
    @success="getTableData"
    ref="edit"
  ></Edit>
  <ImportAll
    @success="getTableData"
    ref="importAll"
  ></ImportAll>
  <BatchCancellation
    @success="getTableData"
    ref="batchCancellation"
  ></BatchCancellation>
  <Details
    ref="details"
  ></Details>
  <ViewBill
    ref="viewBill"
  ></ViewBill>
</div>
</template>

<script>
import Add from "./ExpressOrderManagement_add";
import Edit from "./ExpressOrderManagement_edit";
import ImportAll from "./ExpressOrderManagement_importAll";
import BatchCancellation from "./ExpressOrderManagement_batchCancellation";
import Details from "./ExpressDeliveryOrderManagement_details";
import ViewBill from "./ExpressOrderManagement_viewBill";
export default {
  components: {
    Add,
    Edit,
    ImportAll,
    BatchCancellation,
    Details,
    ViewBill,
  },
  data(){
    return{
      filterItemList:[
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.order_number'),width:200, filterKey: 'order_sn', filterType: 'SearchInput', placeholderStr: null },
        // 日期选择器
        { label:this.$t('ExpressOrderManagementLang.Order_Date'),width:200, filterKey: 'order_date', filterType: 'SearchDate' },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.line'),width:200, filterKey: 'lid', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:[],label:'name_current',value:'lid'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.sale'),width:200, filterKey: 'order_sale_uid', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:[],label:'name',value:'uid'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_shipping_status'),width:200, filterKey: 'trans_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:[],label:'name',value:'id'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_billing_status'),width:200, filterKey: 'out_bill_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:[],label:'name',value:'id'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_payment_status'),width:200, filterKey: 'pay_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:[],label:'name',value:'id'} },
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.Origin'),width:200, filterKey: 'start_local_name', filterType: 'SearchInput', placeholderStr: null },
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.destination'),width:200, filterKey: 'target_local_name', filterType: 'SearchInput', placeholderStr: null },
      ],
      filterData:{
        page: "",
        limit: "30",
        order: "",
        type:1,

        order_sn: "",
        order_date:[],
        order_date1: "",
        order_date2: "",
        lid: "",
        order_sale_uid: "",
        trans_status: "",
        out_bill_status: "",
        pay_status: "",
        start_local_name: "",
        target_local_name: "",
      },
      lineoptions:[],
      saleoptions:[],
      shippingoptions:[],
      billingoptions:[],
      paymentoptions:[],
      tableColumn: [
        {
          label: "",
          prop: "table_code",
          width:40,
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Order_information'),
          prop: "Order_information_value",
          width: 250,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Order_time'),
              prop: "create_order_time",
            },
            {
              label: this.$t('ExpressOrderManagementLang.order_number'),
              prop: "order_sn",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Order_remarks'),
              prop: "remark",
              istooltip:true,
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Order_status'),
          prop: "Order_status_value",
          width: 140,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Transportation_status'),
              prop: "trans_status_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Out_bill_status'),
              prop: "out_bill_status_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Payment_status'),
              prop: "pay_status_name",
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Shipper_information'),
          prop: "Shipper_information_value",
          width: 140,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Shipper'),
              prop: "order_uid_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.sale'),
              prop: "order_sale_uid_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.discount'),
              prop: "discount",
            },
            // {
            //   label: this.$t('ExpressOrderManagementLang.VIP_level'),
            //   prop: "VIP_level_value",
            // },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Route_information'),
          prop: "Route_information_value",
          width: 140,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Line_name'),
              prop: "line_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Origin'),
              prop: "start_local_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.destination'),
              prop: "target_local_name",
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.take_goods_method'),
          prop: "Receipt_information_value",
          width: 200,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Delivery_method'),
              prop: "pickup_type_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.name_sender'),
              prop: "pickup_name",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Sender_phone_number'),
              prop: "pickup_tel",
            },
            {
              label: this.$t('ExpressOrderManagementLang.return_address'),
              prop: "pickup_addr",
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Weighing_information'),
          prop: "Weighing_information_value",
          width: 140,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Gross_weight_goods'),
              prop: "gross_weight",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Cargo_weighing'),
              prop: "weight",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Volume_goods'),
              prop: "volume",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Cargo_volumeing'),
              prop: "cal_volume",
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.additional_information'),
          prop: "additional_information_value",
          width: 140,
          is_additional:true,//是否为自增信息列
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.Order_cost'),
          prop: "Order_cost_value",
          width: 140,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.freight'),
              prop: "bill_trans_price",
            },
            {
              label: this.$t('ExpressOrderManagementLang.service_charge'),
              prop: "bill_survey_price",
            },
            {
              label: this.$t('ExpressOrderManagementLang.insurance_premium'),
              prop: "bill_insure_price",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Total_cost'),
              prop: "total_price",
            },
          ]
        },
        {
          checked: true,
          label: this.$t('ExpressOrderManagementLang.time'),
          prop: "time_value",
          width: 220,
          MoreContant:[
            {
              label: this.$t('ExpressOrderManagementLang.Order_time'),
              prop: "create_order_time",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Transportation_time'),
              prop: "trans_time",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Delivery_time'),
              prop: "arrival_time",
            },
            {
              label: this.$t('ExpressOrderManagementLang.Payment_Time'),
              prop: "pay_time",
            },
          ]
        },
      ],
      tableData: [],

      pageinfo: {
        page: 1,
        page_all: 1,
        limit: 30,
        number_all: 0,
      },
      sendDataObj:{},
    }
  },
  computed: {
      tabsId() {
          return this.$store.state.tabsId;
      }
  },
  mounted(){
    this.getOptionsList()
    this.getHeaderList()
    this.getTableData()
  },
  methods:{
    // 获取下拉单列表
    async getOptionsList() {
      await this.$get("screenLines",{type:1}).then((res) => {
        this.lineoptions = res.data;
      });
      await this.$get("allChilds").then((res) => {
        this.saleoptions = res.data;
      });
      await this.$get("billSysItems").then((res) => {
        this.shippingoptions = res.data.trans_status;
        this.billingoptions = res.data.bill_status;
        this.paymentoptions = res.data.order_pay_type;
      });
      this.filterItemList=[
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.Express_Number'),width:200, filterKey: 'order_sn', filterType: 'SearchInput', placeholderStr: null },
        // 日期选择器
        { label:this.$t('ExpressOrderManagementLang.Order_Date'),width:200, filterKey: 'order_date', filterType: 'SearchDate' },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.line'),width:200, filterKey: 'lid', filterType: 'SearchFilterSelect', placeholderStr: null, filterOptions: {options:this.lineoptions,label:'name_current',value:'lid'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.sale'),width:200, filterKey: 'order_sale_uid', filterType: 'SearchFilterSelect', placeholderStr: null, filterOptions: {options:this.saleoptions,label:'name',value:'uid'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_shipping_status'),width:200, filterKey: 'trans_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:this.shippingoptions,label:'name',value:'id'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_billing_status'),width:200, filterKey: 'out_bill_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:this.billingoptions,label:'name',value:'id'} },
        // 下拉框
        { label:this.$t('ExpressOrderManagementLang.Order_payment_status'),width:200, filterKey: 'pay_status', filterType: 'SearchSelect', placeholderStr: null, filterOptions: {options:this.paymentoptions,label:'name',value:'id'} },
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.Origin'),width:200, filterKey: 'start_local_name', filterType: 'SearchInput', placeholderStr: null },
        // input输入框
        { label:this.$t('ExpressOrderManagementLang.destination'),width:200, filterKey: 'target_local_name', filterType: 'SearchInput', placeholderStr: null },
      ]
    },
    //查询
    search(){
      this.getTableData()
    },
    //清空
    clear(){
      this.filterData.order_sn= "",
      this.filterData.order_date=[],
      this.filterData.order_date1= "",
      this.filterData.order_date2= "",
      this.filterData.lid= "",
      this.filterData.order_sale_uid= "",
      this.filterData.trans_status= "",
      this.filterData.out_bill_status= "",
      this.filterData.pay_status= "",
      this.filterData.start_local_name= "",
      this.filterData.target_local_name= "",
      this.getTableData()
    },
    // 获取表头组
    getHeaderList(){
      this.$get("get_th",{menu_id:this.tabsId}).then((res) => {
        if(!!res.data.th_json){
          this.tableColumn=JSON.parse(res.data.th_json)
        }
      });
    },
    //保存表头表头组
    keepHeaderList(){
        let params = new FormData();
        params.append("menu_id", this.tabsId);
        params.append("th_json", JSON.stringify(this.tableColumn));
        this.$postForm("save_th", params).then((res) => {
          
        });
    },
    // 更改分页
    SetPagination(data){
      this.filterData.page=data.page
      this.filterData.limit=data.limit
      this.pageinfo.page=data.page
      this.pageinfo.limit=data.limit
      this.getTableData()
    },
    pushButton(route) {

      if (route == "add") {
        this.$refs.add.init();
      } else if (route == "edit") {
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          if(this.sendDataObj.is_allow_edit===1){
            this.$refs.edit.init(this.sendDataObj);
          }else{
            this.$message.warning(this.$t('ExpressOrderManagementLang.message_text'));
          }
        }
      } else if (route == "importAll") {
        this.$refs.importAll.init();
      } else if (route == "cancellationOrder") {
        if (JSON.stringify(this.sendDataObj) == "{}") {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          if (this.sendDataObj.out_bill_status!==0) {
            this.$message.warning(this.$t('ExpressOrderManagementLang.message_text1'));
          } else {
            let params = new FormData();
            params.append("order_sn", this.sendDataObj.order_sn);
            this.$postForm('cancelOrder',params).then((res) => {
              if(res.success){
                this.$message.success(res.msg);
                this.getTableData()
              }
            })
          }
        }
      } else if (route == "BatchCancellation") {
        this.$refs.batchCancellation.init();
      } else if (route == "viewBill") {
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.viewBill.init(this.sendDataObj);
        }
      } else if (route == "export") {
        if(this.tableData.length===0){
          this.$message.warning(this.$t('common.noData'));
          return
        }
        this.$downloadCenterLoad('exportOrderData',this.filterData);
      }
    
    },
    // 获取表格数据
    getTableData(){
      this.$get("orderList", this.filterData).then((res) => {
        this.tableData = res.data;
        this.pageinfo = res.pageinfo;
        this.pageinfo.limit=Number(this.pageinfo.limit)
        this.sendDataObj={}
      });
    },
    setCurrent(data){
      this.sendDataObj=data
    },
    cellDblclick(obj){
      let row=obj.row
      this.$refs.details.init(row,'details');
    },
  }
}
</script>
<style scoped lang="less">
.tableBox {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/deep/.vxe-cell{
  padding-top: 5px;
  padding-bottom: 5px;
}
.moreContant{
  display: flex;
  flex-direction: column;
  // .tooltip{
  //   display: inline-block;
  //   width: 100%;
  // }
}
</style>